<?php    
    # Suorita haku
    $search = API::trainingProgramSearch($_POST);
?>

<table class="table table-hover">
    <thead>
        <tr>
            <th>
                &nbsp;
            </th>
            <th>
                Name
            </th>
            <th>
                Start date
            </th>
            <th>
                End date
            </th>
            <th>
                Workouts
            </th>
            <th>
                &nbsp;
            </th>
        </tr>
    </thead>
    
    <tbody>
        <?php
            $list = (array)arrGet($search,"list");
            foreach ($list as $row) {
                $hashid = htmlescape($row["hashid"]);
                $name = htmlescape($row["program_name"]);
            ?>
                <tr>
                    <td>
                        <a class="a-navigation"
                          data-hashid="<?php echo $hashid; ?>"
                          data-ui-view="edittrainingprogram"
                          href="#">
                            EDIT
                        </a>
                        &nbsp;
                        <a class="a-navigation"
                          data-hashid="<?php echo $hashid; ?>"
                          data-ui-view="addtrainingprogram"
                          data-copy="1"
                          href="#">
                            COPY
                        </a>
                    </td>
                    <td>
                        <a class="a-subview-dialog"
                          data-ui-view="tplist"
                          data-ui-subview="info"
                          data-ui-title="<?php echo $name; ?>"
                          data-hashid="<?php echo $hashid; ?>"
                          href="#">
                            <?php echo $name; ?>
                        </a>
                    </td>
                    <td>
                        <?php echo htmlescape($row["startdate"]); ?>
                    </td>
                    <td>
                        <?php echo htmlescape($row["enddate"]); ?>
                    </td>
                    <td>
                        <?php echo htmlescape($row["workout_count"]); ?>
                    </td>
                    <td>
                        <?php
                            FT::$autoescape = false;
                            FT::button("<span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span>",array(
                                "class"         => "tplist-button-delete-tp btn btn-default btn-xs",
                                "data-hashid"   => $hashid,
                                "title"         => "Delete training program"
                            ));
                            FT::$autoescape = true;
                        ?>
                    </td>
                </tr>
            <?php
            }
        ?>
    </tbody>
</table>

<strong>Total training programs:</strong>

<?php
    # Selvitetään positiot
    $pos        = arrGet($_POST,"pos",0);
    $count      = arrGet($_POST,"count",0);
    $totalCount = arrGet($search,"totalCount",0);
    
    # Yhteensä
    echo htmlescape($totalCount);
        
    # Näytä navigointi
    echo createPagination("tplist-a-pagination",$pos,$count,$totalCount);
?>